<template>
  <div class="my-likes">
    <x-header>我的收藏</x-header>
    <scroller :noDataText="noDataText" :on-refresh="refresh" :on-infinite="infinite" style="padding-top:46px;min-height: 500px;" ref="my_scroller">
      <div class="commentList">
        <div class="collection-item" @click.native="$router.push(`/detail/${item._id}`)" v-for="(item,i) in list" :key="i">
          <div class="top">
            <div class="left">
              <avatar :src="item.creator && item.creator.avatar" username="Lairenna Doe" :size="40"></avatar>
            </div>
            <div class="right">
              <div class="right-1">
                <div>{{item.creator && item.creator.nickname}}</div>
                <div>
                  <span>{{getTime(item.createTime)}}</span>
                  <span class="item-from">来自#{{item.category}}#</span>
                </div>
              </div>
              <div class="right-2">
                <i style="color:#EFA79B;" class="icon-home_ico_like-" @click="handleFocusman"></i>
              </div>
            </div>
          </div>
        </div>
      </div>
    </scroller>
  </div>
</template>
<script>
import { Vue, Component } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
import Avatar from 'vue-avatar';
import { formatMsgTime } from '../../js/getTime'
import { getUnixTime } from '../../js/utils'
import {
  Actionsheet,
  XHeader,
  Group,
  Cell
} from 'vux';
const IndexStore = namespace('mine');

@Component({
  components: {
    Actionsheet,
    XHeader,
    Group,
    Cell,
    Avatar
  }
})
export default class MyCollection extends Vue {
  @IndexStore.Action getCollects;
  @IndexStore.State myCollects;
  list = []
  currentPage = 1
  pageSize = 10
  creatTime = null
  noDataText = '--我也是有底线的--'
  infinite () {
    this.init()
    this.currentPage++
    setTimeout(() => {
      this.$refs.my_scroller.finishInfinite(true)
    }, 1000)
  }
  myTime = new Date()
  refresh () {
    this.myTime = new Date()
    setTimeout(() => {
      this.list = []
      this.currentPage = 1
      this.$refs.my_scroller.finishPullToRefresh()
    }, 1000)
  }
  getTime (t) {
    return formatMsgTime(t * 1000)
  }
  handleFocusman (val) {
    const params = {
      status: 1
    }
    this.getWatchUser(params).then(msg => {
      if (msg) {
        this.$vux.toast.text(msg, 'middle');
      } else {
        this.$vux.toast.text('已取消点赞', 'middle');
      }
    })
  }
  created () {
    // this.init()
  }
  init () {
    const params = {
      current: this.currentPage,
      createTime: getUnixTime(this.myTime),
      pageSize: this.pageSize
    }
    this.getCollects(params).then(msg => {
      if (msg) {
        this.$vux.toast.text(msg, 'middle');
      } else {
        const { list } = this.myCollects
        this.list = this.list.concat(list)
      }
    })
  }
}
</script>
<style lang="less">
.my-likes {
  padding-top: 51px;
  .collection-item {
    width: 95%;
    margin: 0 auto;
    border-radius: 10px;
    background: #ffffff;
    padding: 10px 20px;
    box-sizing: border-box;
    margin-top: 5px;
    margin-bottom: 5px;
  }
  .commentList {
      // font-size: 12px;
      .main {
        // font-size: 12px;
      }
      .weui-cells {
        margin-top: 0;
      }
      .weui-cell__ft {
        text-align: left;
        width: 100%;
      }
      .top {
        width: 100%;
        height: 70px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .left {
          width: 20%;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
        }
        .right {
          // font-size: 12px;
          width: 80%;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: space-between;
        }
        .right-1 {
          display: flex;
          flex-direction: column;
        }
        .right-2 {
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }
}
</style>
